import socket
import threading


def thread_process(s):
    while True:
        content = s.recv(1024)
        if len(content) == 0:
            break
        s.send(content.upper())
        print(str(content, encoding="utf-8"))
        # s.close()


server = socket.socket()
server.bind(("127.0.0.1", 8999))
server.listen(5)


while True:
    s, addr = server.accept()

    new_thread = threading.Thread(target=thread_process, args=(s, ))
    print("new thread process content addr: {}".format(addr))
    new_thread.start()
